﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="List.aspx.cs" Inherits="VirtualOrg.Web.FormListProject" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">

        function CreateOrg() {
            if (jQuery('#form1').validationEngine('validate') == true) {
                var subcategoryId = 0;
                var otherCategory = "";

                var name = document.getElementById('<%=txtName.ClientID %>').value;
                var tagline = document.getElementById('<%=txtTagline.ClientID %>').value;
                var description = document.getElementById('<%=txtDescription.ClientID %>').value;
                var categoryCtl = document.getElementById("<%=ddlCategory.ClientID %>");
                var categoryId = categoryCtl.options[categoryCtl.selectedIndex].value;

                if (categoryCtl.options[categoryCtl.selectedIndex].text != "") {
                    if (categoryCtl.options[categoryCtl.selectedIndex].text != "Other") {
                        var subcategoryCtl = document.getElementById("<%=ddlSubCategory.ClientID %>");
                        var subcategoryId = subcategoryCtl.options[subcategoryCtl.selectedIndex].value;
                    }
                    else {
                        var otherCategory = document.getElementById('<%=txtOtherCategory.ClientID %>').value;
                    }
                }

                ob_post.AddParam("title", name);
                ob_post.AddParam("tagline", tagline);
                ob_post.AddParam("description", description);
                ob_post.AddParam("categoryId", categoryId);
                ob_post.AddParam("subcategoryId", subcategoryId);
                ob_post.AddParam("otherCategory", otherCategory);

                ob_post.post(null, "CreateOrg", CreateOrgResponse);
            }

            return false;
        }

        function CreateOrgResponse(result) {
            if (result == "true") {
                window.location.href = "Update.aspx?info";
            }
            else {
                msgboxpanel.innerHTML = result;
            }
        }

        function CheckOrgname() {
            var username = document.getElementById('<%=txtName.ClientID %>').value;
            ob_post.AddParam("searchText", username);

            ob_post.post(null, "CheckOrgName", CheckOrgNameResponse);
        }

        function CheckOrgNameResponse(result) {
            var username = document.getElementById('<%=txtName.ClientID %>').value;
            if (result) {
                spanOrgnameCheck.innerText = "'" + username + "' is available";
                spanOrgnameCheck.style.color = "Green";
            }
            else {
                spanOrgnameCheck.innerText = "'" + username + "' is not available";
                spanOrgnameCheck.style.color = "Red";
            }
        }
    </script>
    <div id="main" class="ui-widget-content ui-corner-all" style="padding-left: 30px;">
        <h2>
            Create an virtual organization</h2>
        <hr />
        <asp:UpdatePanel ID="pnlUpdate" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <table style="width: 100%; height: 350px;">
                    <tr>
                        <td>
                            <label for="author">
                                Category:</label>
                            <asp:DropDownList ID="ddlCategory" AutoPostBack="true" CssClass="validate[required] select_field ui-corner-all"
                                runat="server" OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="author">
                                Sub Category:</label>
                            <asp:DropDownList ID="ddlSubCategory" CssClass="select_field ui-corner-all" runat="server">
                            </asp:DropDownList>
                            <asp:TextBox ID="txtOtherCategory" Visible="false" runat="server" CssClass="input_field ui-corner-all"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="author">
                                Name:</label>
                            <asp:TextBox ID="txtName" onchange="CheckOrgname();" runat="server" CssClass="validate[required,minSize[3]] input_field ui-corner-all"
                                Width="400px"></asp:TextBox>
                            - Virtual Org &nbsp;&nbsp;&nbsp; <span id="spanOrgnameCheck" style="font-weight: bold;
                                font-size: 11px;"></span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="author">
                                Tagline:</label>
                            <asp:TextBox ID="txtTagline" runat="server" CssClass="validate[required,minSize[10]] input_field ui-corner-all"
                                Width="400px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="author">
                                Description:</label>
                            <asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="validate[required,minSize[50]] input_field ui-corner-all"
                                Width="400px"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlCategory" EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>
        <div class="cleaner h10">
        </div>
        <asp:Button ID="btnCreate" OnClientClick="return CreateOrg();" runat="server" Text="Start here" />
        <div class="cleaner">
        </div>
    </div>
</asp:Content>
